var Avatar = false;
var Player = new Object;
Player.x = 0;
Player.y = 0;
Player.avatar = new Array("", "/resources/players/green.gif", "/resources/players/green.gif", "/resources/players/green.gif", "/resources/players/green.gif");
Player.facing = NORTH;

function LoadPlayer()
 {
  


dwr.engine.beginBatch();
Avatar = document.createElement('IMG');
 PlayerMove.playerName( function(data) {
	 //alert("data = " + data);
	  Avatar.id = data;
  });




//alert("Avatar.id = = " + Avatar.id);

//Avatar.id = 'player';

  Avatar.className = "iplayer";
  Avatar.src = Player.avatar[Player.facing];
  Avatar.style.top=IPixels[Player.x];
  Avatar.style.left=IPixels[Player.y];
  Avatar.zIndex = '3';
  //alert("Pixels[Player.x] = " + IPixels[Player.x]);
  //alert("Pixels[Player.y] = " + IPixels[Player.y]);
  document.getElementById('pov').appendChild(Avatar);

 dwr.engine.endBatch({
  async:false
});
 }


function moveEast() {
  Player.y += 1;
UpdateAvatar();
}

function moveSud() {
  Player.x += 1;
  UpdateAvatar();
}

function moveWest() {
  Player.y -= 1;
UpdateAvatar();
}

function moveNorth() {
  Player.x -= 1;
UpdateAvatar();
}

function moveNorthEast() {
  Player.x -= 1;
  Player.y += 1;
  UpdateAvatar();
}

function moveSudEast() {
 Player.y += 1;
  Player.x += 1;
  UpdateAvatar();
}

function moveSudWest() {
 Player.x += 1;
  Player.y -= 1;
  UpdateAvatar();
}

function moveNordWest() {
Player.x -= 1;
  Player.y -= 1;
  UpdateAvatar();
}




function UpdateAvatar() {

// se e' diverso da 0 non si cammina
//alert(Map[Player.x][Player.y]);

  Avatar.style.top=IPixels[Player.x];
  Avatar.style.left=IPixels[Player.y];


}


function initPlayer() {
	 PlayerMove.init();
}

function SmoveEast() {
	
	PlayerMove.moveEast();
}

function SmoveSud() {

	PlayerMove.moveSud();
}

function SmoveWest() {
	PlayerMove.moveWest();
}

function SmoveNorth() {
	PlayerMove.moveNorth();
}

function SmoveNorthEast() {
	PlayerMove.moveNorthEast();
}

function SmoveSudEast() {
	PlayerMove.moveSudEast();
}

function SmoveSudWest() {
	PlayerMove.moveSudWest();
}

function SmoveNordWest() {
	PlayerMove.moveNordWest();
}


function updatePlayer(info) {

	//alert(info.x);
	//alert(info.y);
 
  Avatar.style.top=IPixels[info.x];
  Avatar.style.left=IPixels[info.y];
}